{extend name="public/base" /}
{block name="content"}
<div class="page-content">
    <!-- Page Breadcrumb -->
    <div class="page-breadcrumbs">
        <ul class="breadcrumb">
            <li class="active">
                <i class="fa fa-home"></i>&nbsp;管理员管理
            </li>
            <li>管理员列表</li>
        </ul>
    </div>
    <!-- /Page Breadcrumb -->
    <!-- Page Body -->
    <div class="page-body">
        <a href="{:url('admin/home/adminadd')}" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i>&nbsp;管理员添加</a>
        <div class="row">
            <div class="col-xs-12">
                <div class="widget">
                    <div class="widget-header">
                        <span class="widget-caption">管理员列表</span>
                        <div class="widget-buttons">
                            {$admins->render()|raw|replace}
                        </div>
                    </div>
                    <div class="widget-body">
                        <table class="table table-hover table-bordered">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>昵称</th>
                                <th>账号</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="admins" id="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.nickname}</td>
                                <td>{$vo.username}</td>
                                <td>{if $vo.status == 1}正常{else /}禁用{/if}</td>
                                <td>
                                    {if $vo.status == 1}
                                    <a href="#" dataid="{$vo.id}" datastatus="{$vo.status}" class="btn btn-warning btn-xs adminDis">禁用</a>
                                    {else /}
                                    <a href="#" dataid="{$vo.id}" datastatus="{$vo.status}" class="btn btn-success btn-xs adminDis">启动</a>
                                    {/if}
                                    <a href="{:url('admin/home/adminedit', ['id' => $vo.id])}" class="btn btn-azure btn-xs">编辑</a>
                                    <a href="#" dataid="{$vo.id}" class="btn btn-danger btn-xs adminDel">删除</a>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /Page Body -->
</div>
{/block}
{block name="js"}
{__block__}
<script>
    $('.pagination').addClass('pagination-sm');
    if ({:session('admin.id')} != 1) {
        $('.adminDis').addClass('hidden');
    }
    $('.adminDis').click(function () {
        var id = $(this).attr('dataid');
        var status = $(this).attr('datastatus');
        if (status == 1) {
            var msg = '确定禁用此账号吗？';
        }else {
            var msg = '确定启用此账号吗？';
        }
        layer.confirm(msg, {
            icon:3,
            title:'操作账号'
        }, function (index) {
            layer.close(index);
            $.ajax({
                url:"{:url('admin/home/admindisabled')}",
                type:'post',
                data:{id: id, status: status},
                dataType:'json',
                success:function (data) {
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon:6,
                            time:2000
                        }, function () {
                            location.href = data.url;
                        });
                    }else {
                        layer.open({
                            title:'操作失败',
                            content:data.msg,
                            icon:5,
                            anim:6
                        });
                    }
                }
            });
        });
        return false;
    });

    $('.adminDel').click(function () {
        var id = $(this).attr('dataid');
        layer.confirm('确定删除吗？', {
            title:'删除账号',
            icon:3
        }, function (index) {
            layer.close(index);
            $.ajax({
                url:"{:url('admin/home/admindel')}",
                type:'post',
                data:{id: id},
                dataType:'json',
                success:function (data) {
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon:6,
                            time:2000
                        }, function () {
                            location.href = data.url;
                        });
                    }else {
                        layer.open({
                            title:'操作失败',
                            content:data.msg,
                            icon:5,
                            anim:6
                        });
                    }
                }
            });
        });
        return false;
    });
</script>
{/block}
